﻿using DDD.EFCore;
using MediatR;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OrderModule.Infrastructure
{
    public class OrderModuleCommandUnitOfWorkBehavior<TCommand, TResponse>(OrderModuleDbContext context)
        : DDD.EFCore.Shared.CommandUnitOfWorkBehavior<TCommand, TResponse>
        where TCommand : notnull
    {

        public override async Task<TResponse> Handle(TCommand request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
        {
            var response = await next();
            await context.SaveUnitOfWorkAsync(cancellationToken);
            return response;
        }
    }
}
